package cn.doitedu.dwetl.utls

import cn.doitedu.dwetl.beans.EventLogBean
import org.apache.spark.sql.Row

/**
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @Author hunter@doitedu.cn
 * @date 2020/8/215:59     
 */
object BeanUtil {

  def row2EventLogBean(row: Row): EventLogBean = {

    try {
      val account = row.getAs[String]("account")
      val appid = row.getAs[String]("appid")
      val appversion = row.getAs[String]("appversion")
      val carrier = row.getAs[String]("carrier")
      val deviceid = row.getAs[String]("deviceid")
      val devicetype = row.getAs[String]("devicetype")
      val eventid = row.getAs[String]("eventid")
      val ip = row.getAs[String]("ip")
      val latitude = row.getAs[Double]("latitude")
      val longitude = row.getAs[Double]("longitude")
      val nettype = row.getAs[String]("nettype")
      val osname = row.getAs[String]("osname")
      val osversion = row.getAs[String]("osversion")
      val releasechannel = row.getAs[String]("releasechannel")
      val resolution = row.getAs[String]("resolution")
      val sessionid = row.getAs[String]("sessionid")
      val timestamp = row.getAs[Long]("timestamp")

      val properties: collection.Map[String, String] = row.getMap[String, String](13)


      EventLogBean(account, appid, appversion, carrier, deviceid, devicetype, eventid, ip,
        latitude, longitude, nettype, osname, osversion, properties, releasechannel,
        resolution, sessionid, timestamp)
    } catch {
      case e: Exception => null
    }
  }

}
